package com.shuyun.classloader.jar;

import java.net.URL;
import java.net.URLClassLoader;
import java.util.Map;

/**
 * @description:
 * @author: shuai.chen@shuyun.com
 * @date: 2021/8/23 3:17 下午
 */
public class LoadJarTest {

    public static void main(String[] args) throws Exception {
        String location = "https://shuai-blog.oss-cn-hangzhou.aliyuncs.com/outer-jar.jar";
        URL jarURL = new URL("jar:" + location + "!/");
        Map<String, IProtocol> protocolMap = ProtocolManager.loadProtocol(jarURL);
        System.out.println(protocolMap.get("淘宝"));
        protocolMap.get("淘宝").handle();

        System.out.println("=====获取指定jar下的某个类实例=====");
        IProtocol protocol = ProtocolManager.loadProtocol(jarURL, "com.shuyun.open.protocol.JDProtocol");
        protocol.handle();

//        URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { jarURL });
//        IProtocol protocol2 = (IProtocol) urlClassLoader.loadClass("com.shuyun.open.protocol.JDProtocol").newInstance();
//        protocol2.handle();
    }

}
